/**
 *
 * 2007-11-4 下午03:20:14
 * @author xuhuan
 */

package edu.ccut.saturn.studio.action;

import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.ui.actions.ActionRegistry;
import org.eclipse.gef.ui.actions.GEFActionConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.ui.actions.ActionFactory;

import edu.ccut.saturn.studio.logic.contextaction.Change;
import edu.ccut.saturn.studio.logic.contextaction.OpenLogicAction;

public class ActionEditorContextMenuProvider extends ContextMenuProvider {
	private ActionRegistry actionRegistry;

	public ActionEditorContextMenuProvider(EditPartViewer viewer) {
		super(viewer);

	}

	public ActionEditorContextMenuProvider(EditPartViewer viewer,
			ActionRegistry registry) {
		super(viewer);
		if (registry == null) {
			throw new IllegalArgumentException();
		}
		actionRegistry = registry;
	}

	@Override
	public void buildContextMenu(IMenuManager menu) {
		GEFActionConstants.addStandardActionGroups(menu);

		// Add actions to the menu
		menu.appendToGroup(GEFActionConstants.GROUP_UNDO, // target group id
				getAction(ActionFactory.UNDO.getId())); // action to add
		menu.appendToGroup(GEFActionConstants.GROUP_UNDO,
				getAction(ActionFactory.REDO.getId()));
		menu.appendToGroup(GEFActionConstants.GROUP_EDIT,
				getAction(ActionFactory.DELETE.getId()));
		menu.appendToGroup(GEFActionConstants.GROUP_REST,
				getAction(OpenLogicAction.ACTION_OPEN_MODEL));
		menu.appendToGroup(GEFActionConstants.GROUP_REST,
				getAction(ActionFactory.COPY.getId()));
		menu.appendToGroup(GEFActionConstants.GROUP_REST,
				getAction(ActionFactory.PASTE.getId()));

		menu.appendToGroup(GEFActionConstants.GROUP_REST, getAction(Change.ID));
//		menu.appendToGroup(GEFActionConstants.GROUP_REST,
//				getAction(DebugAction.EDITOR_DEBUG_ID));
	}

	private IAction getAction(String actionId) {
		return actionRegistry.getAction(actionId);
	}
}
